package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjPendingBean;
import com.koron.css2.newProjectCenter.bean.query.PjPendingQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjPendingMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 工程挂起列表查询
 */
public class PjPendingList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjPendingQueryBean pjPendingQuery = JsonUtils.objectToPojo(req.getData(), PjPendingQueryBean.class);
            PjPendingMapper pjPendingMapper = factory.getMapper(PjPendingMapper.class);

            // 1. 设置分页参数
            PageHelper.startPage(pjPendingQuery.getPage(), pjPendingQuery.getPageCount());
            // 2. 查询数据
            List<PjPendingBean> pjDelayList = pjPendingMapper.selectList(pjPendingQuery);
            // 3. 返回结果
            MessageBean<PageInfo> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"延期列表查询成功", PageInfo.class);
            messageBean.setData(new PageInfo<>(pjDelayList));
            return messageBean;
        } catch (Exception e) {
            logger.error("延期列表查询失败",e);
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"延期列表查询失败",null);
        }
    }
}